# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=etcd
pkgver=3.5.16
pkgrel=0
pkgdesc="A highly-available key value store for shared configuration and service discovery"
url="https://github.com/etcd-io/etcd"
license="Apache-2.0"
arch="all"
makedepends="go bash"
install="$pkgname.pre-install"
provides="etcd-api"
provider_priority=2
options="net chmod-clean"
pkgusers="etcd"
pkggroups="etcd"
subpackages="$pkgname-doc $pkgname-ctl $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/etcd-io/etcd/archive/v$pkgver.tar.gz
	git-sha.patch
	$pkgname.yaml
	$pkgname.confd
	$pkgname.initd
	"

build() {
	export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
	export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
	export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
	export GOFLAGS="$GOFLAGS -mod=mod"
	export CGO_ENABLED=1

	GIT_SHA="$(git ls-remote https://github.com/coreos/etcd.git refs/tags/v$pkgver | awk '{print $1}')" \
		bash -x ./build.sh
}

package() {
	install -d -o "$pkgusers" -g "$pkggroups" -m 700 "$pkgdir"/var/lib/$pkgname
	install -Dm755 bin/etcd "$pkgdir"/usr/bin/etcd
	install -Dm755 bin/etcdctl "$pkgdir"/usr/bin/etcdctl
	install -Dm644 $srcdir/$pkgname.yaml "$pkgdir"/etc/etcd/conf.yml
	install -Dm644 $srcdir/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -Dm755 $srcdir/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

ctl() {
	pkgdesc="A command-line client for etcd"
	amove usr/bin/etcdctl
}

sha512sums="
9a83ce65265dcaa6def855beb8b302bff3e8f4589eb78c454ee0b496bc0c5e9d24eea06bda02ae6d7474029c0cb7410c92997e22db54f53f2717081b6ca05ffc  etcd-3.5.16.tar.gz
0d7d8be227cd401748f6ac5d4621da2873c63d18816fa9102d2e6a2f718f6ba269083eddb82c37d704a083eedee726a23991c0a10eadd1b00e05bb549a580cc3  git-sha.patch
92e6a22dfe12eef76c186c04a4aadca5318300c18aefc979cc03926fddf40e0e9b3bf2b40b75702f2f710dc65420da676c734cfe4d246d86e0728d6e99f43426  etcd.yaml
8b917d2b3a136a97dd9565a91377420ce1f812bfb10bb0caa95f1024dd366cb78ebb0539f16ddfbc399325d41a6664b856d49c5c9aa67bc27e36040f2227356e  etcd.confd
b67f7fd209a29ed2a6ef86d5a3c07cf5dc4138af7c61c3a928471cd79f5579ce7861fd21167db332727dfb2a8e554722366c6505e447f3b2feeae819f869aa11  etcd.initd
"
